feat: use official Cloudflare TypeScript API Library#783
Closed
andykenward wants to merge 3 commits into
Closed
Conversation
Migrate from hand-rolled fetch + @cloudflare/types to the official `cloudflare` npm SDK. The SDK ships with correctly-typed responses (including `aliases: string[] | null`, fixing the old workaround), uses native fetch, and has zero runtime dependencies — so esbuild tree-shaking keeps the bundle impact minimal. Removes ~580 lines of custom fetch/error boilerplate: - fetchResult, fetchSuccess (api/fetch-result.ts) - throwFetchError, renderError (api/fetch-error.ts) - ParseError (api/parse-error.ts) - getCloudflareApiEndpoint (api/endpoints.ts, now handled by SDK) - @cloudflare/types devDependency Adds: - api/client.ts — thin factory for the Cloudflare SDK client - cloudflare 4.5.0 as a bundled dependency Error handling in delete.ts now catches Cloudflare.APIError and inspects the response body for error code 8000009 (already-deleted). Tests updated: APIError replaces ParseError in error assertions. Note: run `pnpm install` to update the lockfile, then `pnpm run all` to verify types, tests, and bundle size. Co-authored-by: Andy Kenward <andykenward@users.noreply.github.com>
- types.ts: replace @cloudflare/types import with cloudflare SDK Deployment type; aliases correctly typed as string[] | null - get.ts: use SDK client to list deployments via async iteration - delete.ts: use SDK client; catch Cloudflare.APIError for code 8000009 - endpoints.ts: remove getCloudflareApiEndpoint (SDK handles URLs); keep CloudflareApiEndpoint type and getCloudflareLogEndpoint - endpoints.test.ts: remove getCloudflareApiEndpoint tests - create.test.ts, status.test.ts: update error assertions to Cloudflare.APIError (was ParseError snapshot) Co-authored-by: Andy Kenward <andykenward@users.noreply.github.com>
|
Owner
Author
|
Cloudflare TypeScript API library is too big and has bad TypeScript types. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #475
Replaces hand-rolled fetch +
@cloudflare/typeswith the officialcloudflarenpm SDK (v4.5.0).Removes ~580 lines of boilerplate:
fetchResult,fetchSuccess,throwFetchError,ParseError(ported from wrangler)getCloudflareApiEndpoint(URL construction now handled by SDK)@cloudflare/typesdevDependencyAdds:
src/common/cloudflare/api/client.ts— thin factory for the SDK clientcloudflare@4.5.0as a bundled dependencyType improvement:
PagesDeploymentis now the SDK'sDeploymenttype directly, removing thealiases: string[] | nullworkaround.Bundle size needs verification: run
pnpm install && pnpm run buildand compare dist size.Generated with Claude Code